package com.situ.mall.controller.front;

import javax.servlet.http.HttpSession;import org.springframework.jdbc.object.UpdatableSqlQuery;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.pojo.entity.User;
import com.situ.mall.util.JSONResult;

@Controller
@RequestMapping("/user")
public class FrontUserController {

	@ResponseBody
	@RequestMapping("/checkUserLogin.shtml")
	public JSONResult checkUserLogin(HttpSession session) {
		User user = (User) session.getAttribute("user");
		if (user == null) {
			return JSONResult.error("请首先登录");
		} else {
			return JSONResult.ok("已经登录");
		}
	}
	
	@ResponseBody
	@RequestMapping("/login.shtml")
	public JSONResult login(User user, HttpSession session) {
		//User loginUser =  userService.login(user);
		if ("zhangsan".equals(user.getUsername()) && "123".equals(user.getPassword())) {
			user.setId(2);
			session.setAttribute("user", user);
			return JSONResult.ok("登录成功");
		} else {
			return JSONResult.error("登录失败");
		}
	}
}
